/*
 * @Author: 
 * @Date: 2022-01-27 10:31:06
 * @LastEditors: lqj
 * @LastEditTime: 2022-02-11 14:11:17
 * @Description: 请填写简介
 */
import React, { Component } from 'react';
import PubSub from 'pubsub-js'

class List extends Component {
  state = {
    searchList: [],
    isFirst: true,
    isLoad: false,
    isError: '',
    isEmpty: false
  }
  componentDidMount() {
    this.token = PubSub.subscribe('initState', (msg, data) => {
      this.setState(data)
    })
  }
  componentWillUnmount() {
    PubSub.unsubscribe(this.token)
  }
  render() {
    const { searchList, isFirst, isLoad, isError } = this.state
    return (
      <div className="row">
        {
          isFirst ? <h5>Welcome to the current page</h5> :
          isLoad ? <div>loading...</div> :
          isError !== '' ? <div style={{color: 'red'}}>{isError}</div> :
          searchList.map(it => {
            return (
              <div key={it.id} className="card">
                <a href={it.html_url} target="_blank" rel="noreferrer">
                  <img alt='attr' src={it.avatar_url} style={{ width: '100px' }} />
                </a>
                <p className="card-text">{it.login}</p>
              </div>
            )
          })
        }
      </div>
    );
  }
}

export default List;
